package com.itheima.web.controller.pms;

import com.itheima.result.ResultData;
import com.itheima.service.pms.PmsBrandService;
import com.itheima.vo.pms.PmsBrand;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("brand")
public class PmsBrandController {
    @DubboReference
    private PmsBrandService pmsBrandService;
    @PostMapping("create")
    public ResultData create(@RequestBody PmsBrand pmsBrand){
        return pmsBrandService.insert(pmsBrand);
    }
    @PostMapping("delete/batch")
    public ResultData batch(@RequestParam List<Integer> ids){
        return pmsBrandService.batch(ids);
    }
    @GetMapping("delete/{id}")
    public ResultData delete(@PathVariable Integer id){
        pmsBrandService.removeById(id);
        return ResultData.ok("操作成功","");
    }
    @GetMapping("list")
    public ResultData list(String keyword,Integer pageNum,Integer pageSize){
        return pmsBrandService.listPage(keyword,pageNum,pageSize);
    }
    @GetMapping("listAll")
    public ResultData liatAll(){
        return ResultData.ok("操作成功",pmsBrandService.list());
    }
    @PostMapping("update/factoryStatus")
    public ResultData factoryStatus(@RequestParam List<Integer> ids,Integer factoryStatus){
        pmsBrandService.updateFactoryStatus(ids,factoryStatus);
        return ResultData.ok("操作成功",ids.size());
    }
    @PostMapping("update/showStatus")
    public ResultData showStatus(@RequestParam List<Integer> ids,Integer showStatus){
        pmsBrandService.updateShowStatus(ids,showStatus);
        return ResultData.ok("操作成功",ids.size());
    }
    @PostMapping("update/{id}")
    public ResultData updateById(@PathVariable Integer id,@RequestBody PmsBrand pmsBrand){
        pmsBrand.setId(id);
        pmsBrandService.updateById(pmsBrand);
        return ResultData.ok("操作成功","");
    }
    @GetMapping("{id}")
    public ResultData getById(@PathVariable Integer id){
        return ResultData.ok("操作成功",pmsBrandService.getById(id));

    }
}
